package com.example.tests;

import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;

import org.testng.annotations.Test;

public class GroupCreationTest extends TestBase {

	@Test(dataProvider = "randomValidGroupGenerator")
	public void testGroupCreationWithValidData(GroupData group)
			throws Exception {
		app.getNavigationHelper().openMainPage();
		app.getGroupHelper().openGroupsPage();

		// save old state
		List<GroupData> oldList = app.getGroupHelper().getGroup();

		// actions
		app.getGroupHelper().initNewGroupCreation();
		app.getGroupHelper().fillGroupForm(app, group);
		app.getGroupHelper().submitGroupCreation();
		app.getGroupHelper().returnToGroupsPage();

		// save new state
		List<GroupData> newList = app.getGroupHelper().getGroup();

		// compare
		oldList.add(group);
		Collections.sort(oldList);
		assertEquals(newList, oldList);

	}
}